<?php

namespace App\Models;

/**
 * Trait AccountLogHelper.
 *
 * @property float|null $available 质押币可用余额
 * @property float|null $disabled  质押币冻结余额
 * @property float|null $freeze  收益币余额
 */
trait AccountLogHelper
{
    public $availableChange;

    public $disabledChange;

    public $freezeChange;

    public static function boot()
    {
        parent::boot();

        static::updating(function ($model) {
            ++$model->version;
        });

        bcscale(8);
    }

    public function availableIncrement($number)
    {
        $this->available = bcadd($this->available, $number);
        $this->availableChange = +$number;
    }

    public function availableDecrement($number)
    {
        $this->available = bcsub($this->available, $number);
        $this->availableChange = -$number;
    }

    public function disabledIncrement($number)
    {
        $this->disabled = bcadd($this->disabled, $number);
        $this->disabledChange = +$number;
    }

    public function disabledDecrement($number)
    {
        $this->disabled = bcsub($this->disabled, $number);
        $this->disabledChange = -$number;
    }

    public function freezeIncrement($number)
    {
        $this->freeze = bcadd($this->freeze, $number);
        $this->freezeChange = +$number;
    }

    public function freezeDecrement($number)
    {
        $this->freeze = bcsub($this->freeze, $number);
        $this->freezeChange = -$number;
    }
}
